var app=getApp();
Page({
  data: {
    userinfo: {},
    flag: '',

  },
  handleGetUserInfo(e) {
    console.log(e);
    const { userInfo } = e.detail;
    wx.setStorageSync("userinfo", userInfo);
    wx.reLaunch({
      url: '/pages/mine/mine',
    })
  },
 
  onShow() {
    const userinfo = wx.getStorageSync("userinfo");
    this.setData({ userinfo })
  },
  logOut() {
    wx.showModal({
      title: '提示',
      content: '你确定要退出登陆吗',
      success: res => {
        if (res.confirm) {
          console.log('用户已确认')
          wx.clearStorage({
            success: (res) => {
              wx.reLaunch({
                url: '/pages/mine/mine',
              })
            },
          })
          //刷新界面
          wx.reLaunch({
            url: '/pages/mine/mine'
          })
        } else {
          console.log('用户已取消')
        }
      }
    })
  },
  //生成商户订单
  generateOrder: function () { 
    var that=this
    var openid=wx.getStorageSync('openid',openid)
    //统一支付返回package
    wx.request({
      url:'http://www.zxapi.top:8080/wxpay/getpayid',
      method:'POST',
      data:{
        "openid":openid,
        "ip":"221.232.59.167",
        "body":"停车支付",
        "total_fee":1
      },
      success:function(res){
        console.log(res);
        var pay=res.data.data
        var timeStamp = pay.timeStamp;
        var packages = pay.package;
        var paySign = pay.paySign;
        var nonceStr = pay.nonceStr;
        var params = { "timeStamp": timeStamp,"nonceStr": nonceStr, "package": packages, "signType": "MD5","paySign": paySign};
        that.pay(params)
      }
    })
  },
  //支付
  pay:function(params){
    console.log(params)
    console.log("支付")
    // console.log(params)
    wx.requestPayment({
      timeStamp: params.timeStamp,
      nonceStr: params.nonceStr,
      package: params.package,
      signType:params.signType,
      paySign: params.paySign,
      success:function(res){
        console.log(res);
      },
      fail:function(res){
        console.log(res)
      }
    })
  }
})